package com.adee.design.create.singlton;

public class ConnectionPool {
    public static void main(String[] args) {
        for(int i = 0; i < 20; i++) {
            new Thread(() -> {
                System.out.println(getInstance());
            }).start();
        }
    }

    private ConnectionPool() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    private static class ThreadPoolHolder {
        public static final ConnectionPool tp = new ConnectionPool(); // ThreadPoolHolder类加载时创建，线程安全
    }
    public static ConnectionPool getInstance() {
        return ThreadPoolHolder.tp;
    }
}
